]>
Commit | Line | Data |
---|---|---|
63a61ee2 BB |
1 | #region Using Statements |
2 | using System; | |
3 | using System.Collections.Generic; | |
4 | using Microsoft.Xna.Framework; | |
5 | using Microsoft.Xna.Framework.Content; | |
6 | using Microsoft.Xna.Framework.Graphics; | |
7 | using Microsoft.Xna.Framework.Input; | |
8 | using Microsoft.Xna.Framework.Storage; | |
9 | using Microsoft.Xna.Framework.GamerServices; | |
b587e9d8 BB |
10 | using Microsoft.Xna.Framework.Media; |
11 | using Microsoft.Xna.Framework.Audio; | |
63a61ee2 BB |
12 | using SuperPolarity; |
13 | #endregion | |
14 | ||
15 | namespace SuperPolarity | |
16 | { | |
17 | /// <summary> | |
18 | /// This is the main type for your game | |
19 | /// </summary> | |
20 | public class SuperPolarity : Game | |
21 | { | |
74c15570 | 22 | public GraphicsDeviceManager graphics; |
63a61ee2 BB |
23 | SpriteBatch spriteBatch; |
24 | ||
38c7d3f9 BB |
25 | public static int OutlierBounds; |
26 | ||
74c15570 BB |
27 | public Player Player; |
28 | ||
29 | Screen EntryScreen; | |
30 | ||
b587e9d8 BB |
31 | protected Song TitleSong; |
32 | protected Song GameSong; | |
33 | protected SoundEffect GameOverSound; | |
74c15570 | 34 | |
63a61ee2 BB |
35 | public SuperPolarity() |
36 | : base() | |
37 | { | |
74c15570 BB |
38 | graphics = new GraphicsDeviceManager(this); |
39 | graphics.PreferMultiSampling = true; | |
40 | graphics.PreferredBackBufferWidth = 1280; | |
41 | graphics.PreferredBackBufferHeight = 720; | |
42 | graphics.ToggleFullScreen(); | |
43 | ||
63a61ee2 | 44 | Content.RootDirectory = "Content"; |
2af83e98 | 45 | ActorFactory.SetGame(this); |
38c7d3f9 BB |
46 | ParticleEffectFactory.SetGame(this); |
47 | ActorManager.SetGame(this); | |
74c15570 BB |
48 | ScreenManager.SetGame(this); |
49 | ||
b587e9d8 | 50 | EntryScreen = (Screen)new TitleScreen(this); |
63a61ee2 BB |
51 | } |
52 | ||
53 | /// <summary> | |
54 | /// Allows the game to perform any initialization it needs to before starting to run. | |
55 | /// This is where it can query for any required services and load any non-graphic | |
56 | /// related content. Calling base.Initialize will enumerate through any components | |
57 | /// and initialize them as well. | |
58 | /// </summary> | |
59 | protected override void Initialize() | |
60 | { | |
63a61ee2 | 61 | base.Initialize(); |
2af83e98 | 62 | |
74c15570 BB |
63 | InputController.RegisterEventForKey("fullScreenToggle", Keys.F11); |
64 | InputController.Bind("fullScreenToggle", HandleFullScreenToggle); | |
38c7d3f9 | 65 | |
74c15570 | 66 | EntryScreen.Initialize(); |
2af83e98 | 67 | |
74c15570 BB |
68 | OutlierBounds = 100; |
69 | } | |
70 | ||
71 | protected void HandleFullScreenToggle(float value) | |
72 | { | |
73 | graphics.ToggleFullScreen(); | |
74 | graphics.ApplyChanges(); | |
63a61ee2 BB |
75 | } |
76 | ||
77 | /// <summary> | |
78 | /// LoadContent will be called once per game and is the place to load | |
79 | /// all of your content. | |
80 | /// </summary> | |
81 | protected override void LoadContent() | |
82 | { | |
b587e9d8 BB |
83 | |
84 | MediaPlayer.IsRepeating = true; | |
85 | GameSong = Content.Load<Song>("Sound\\polaritytheme.wav"); | |
86 | GameOverSound = Content.Load<SoundEffect>("Sound\\gameover"); | |
87 | ||
63a61ee2 BB |
88 | // Create a new SpriteBatch, which can be used to draw textures. |
89 | spriteBatch = new SpriteBatch(GraphicsDevice); | |
90 | ||
b587e9d8 | 91 | ScreenManager.Push(EntryScreen); |
63a61ee2 | 92 | |
b587e9d8 | 93 | Player = new Player(this); |
63a61ee2 BB |
94 | } |
95 | ||
96 | /// <summary> | |
97 | /// UnloadContent will be called once per game and is the place to unload | |
98 | /// all content. | |
99 | /// </summary> | |
100 | protected override void UnloadContent() | |
101 | { | |
102 | // TODO: Unload any non ContentManager content here | |
103 | } | |
104 | ||
105 | /// <summary> | |
106 | /// Allows the game to run logic such as updating the world, | |
107 | /// checking for collisions, gathering input, and playing audio. | |
108 | /// </summary> | |
109 | /// <param name="gameTime">Provides a snapshot of timing values.</param> | |
110 | protected override void Update(GameTime gameTime) | |
111 | { | |
112 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) | |
113 | Exit(); | |
114 | ||
74c15570 | 115 | ScreenManager.Update(gameTime); |
95d7601b | 116 | |
b587e9d8 BB |
117 | Player.Update(); |
118 | ||
63a61ee2 BB |
119 | base.Update(gameTime); |
120 | } | |
121 | ||
122 | /// <summary> | |
123 | /// This is called when the game should draw itself. | |
124 | /// </summary> | |
125 | /// <param name="gameTime">Provides a snapshot of timing values.</param> | |
126 | protected override void Draw(GameTime gameTime) | |
127 | { | |
95d7601b | 128 | GraphicsDevice.Clear(Color.White); |
63a61ee2 BB |
129 | |
130 | spriteBatch.Begin(); | |
131 | ||
74c15570 BB |
132 | ScreenManager.Draw(spriteBatch); |
133 | ||
63a61ee2 BB |
134 | spriteBatch.End(); |
135 | ||
136 | base.Draw(gameTime); | |
137 | } | |
b587e9d8 BB |
138 | |
139 | public void PlaySong(string songName) | |
140 | { | |
141 | // temp stuff before media manager is in | |
142 | if (songName == "game") | |
143 | { | |
144 | MediaPlayer.Play(GameSong); | |
145 | } | |
146 | } | |
147 | ||
148 | public void GameOver() | |
149 | { | |
150 | MediaPlayer.Stop(); | |
151 | GameOverSound.Play(); | |
152 | ScreenManager.Pop(); | |
153 | } | |
63a61ee2 BB |
154 | } |
155 | } |